<template>
  <div class="photo-select">
    <div class="select-header">
      <app-header :active-id="handerActiveId" @handleChangeHeader="handleChangeHeader" />
    </div>
    <div class="select-body">
      <div class="select-body-type">
        <select-body-type :active-id="handerActiveId" />
      </div>
      <!-- <nut-imagepicker
        class="imgs-body"
        @imgMsg="imgMsg"
        :ismultiple="true"
        :imgList.sync="imgList"
        :width="80"
        :height="80"
      ></nut-imagepicker>-->
      <div class="imgs-body" ref="imgsBody">
        <imgage-upload />
        <!-- <div class="img-item add-img-item">
          <input type="file" :id="id" :multiple="true" @change="doUpload" />
          <i class="iconfont maker-jiahao"></i>
        </div> -->

        <div class="img-item" v-for="(item, index) in imgList" :key="index">
          <img src alt />
          <i
            v-if="!numIsOver"
            :class="[item.isChecked ? 'makerdui-selected' : '']"
            class="iconfont makerdui icon-select"
            @click="handleSelectItem(item)"
          ></i>
          <i v-if="numIsOver" class="iconfont makercuo icon-select"></i>
          <span>
            <i class="iconfont makerwarn"></i>
            像素不足
          </span>
        </div>
      </div>
    </div>
    <div class="select-footer">
      <app-footer
        :photo-num="selectedImgNum"
        :need-photo-num="needImgNUm"
        :videoNum="selectedvideoNum"
        :needVideoNum="needVideoNum"
      />
    </div>
  </div>
</template>

<script>
import AppHeader from "./components/AppHeader";
import AppFooter from "./components/AppFooter";
import SelectBodyType from "./components/SelectBodyType";

export default {
  name: "PhotoSelect",
  components: {
    AppHeader,
    AppFooter,
    SelectBodyType,
  },
  computed: {
    getWH() {
      return "22vw";
    },
  },
  data() {
    return {
      id: "upload",
      handerActiveId: 1, // 1 本地
      numIsOver: false,
      imgList: [
        { id: 1, name: "ssss", isChecked: false },
        { id: 2, name: "ssss", isChecked: false },
        { id: 3, name: "ssss", isChecked: false },
        { id: 4, name: "ssss", isChecked: false },
        { id: 5, name: "ssss", isChecked: true },
        { id: 6, name: "ssss", isChecked: false },
        { id: 7, name: "ssss", isChecked: false },
        { id: 8, name: "ssss", isChecked: false },
        { id: 9, name: "ssss", isChecked: false },
        { id: 11, name: "ssss", isChecked: false },
        { id: 12, name: "ssss", isChecked: false },
        { id: 13, name: "ssss", isChecked: false },
        { id: 14, name: "ssss", isChecked: false },
        { id: 15, name: "ssss", isChecked: false },
        { id: 16, name: "ssss", isChecked: false },
        { id: 17, name: "ssss", isChecked: false },
        { id: 18, name: "ssss", isChecked: false },
        { id: 19, name: "ssss", isChecked: false },
        { id: 28, name: "ssss", isChecked: false },
        { id: 29, name: "ssss", isChecked: false },
        { id: 211, name: "ssss", isChecked: false },
        { id: 212, name: "ssss", isChecked: false },
        { id: 213, name: "ssss", isChecked: false },
        { id: 214, name: "ssss", isChecked: false },
        { id: 215, name: "ssss", isChecked: false },
        { id: 216, name: "ssss", isChecked: false },
        { id: 217, name: "ssss", isChecked: false },
        { id: 218, name: "ssss", isChecked: false },
        { id: 219, name: "ssss", isChecked: false },
      ],
      needImgNUm: 3,
      selectedImgNum: 0, // 选中的个数
      needVideoNum: 1,
      selectedvideoNum: 1,
    };
  },
  mounted() {},
  methods: {
    // 获取本地图片
    doUpload() {
      const files = document.getElementById(this.id);
      console.log("imgList=", files.files);
    },
    // 选择头部
    handleChangeHeader(d) {
      this.handerActiveId = d;
    },
    // 选择图片
    handleSelectItem(item) {
      if (this.selectedImgNum === 3) {
        this.$dialog({
          title: "提示",
          content: "选择不能超过30个",
          noOkBtn: true,
          cancelBtnTxt: "知道了",
          customClass: "custom-class",
        });
        return;
      }
      item.isChecked = !item.isChecked;
      console.log("imgList=", this.imgList);
      this.selectedImgNum = 0;
      this.imgList.forEach((item) => {
        if (item.isChecked) this.selectedImgNum++;
      });
    },
  },
};
</script>

<style scoped lang="scss">
.photo-select {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  .select-header {
    width: 100vw;
    height: 6vh;
  }
  .select-body {
    width: 100vw;
    height: 85vh;
    .select-body-type {
      height: 8vh;
      width: 100%;
    }
    .imgs-body {
      width: 100vw;
      max-height: 77vh;
      overflow: auto;
      display: flex;
      justify-content: flex-start;
      flex-wrap: wrap;
      padding: 0 1vw 0 2vw;
      .img-item {
        width: 22vw;
        height: 22vw;
        margin: 1vw 1vw;
        // background-color: pink;
        box-sizing: border-box;
        border: 1px dashed #cccccc;
        position: relative;
        .icon-select {
          font-size: 20px;
          color: #ffffff;
          position: absolute;
          top: 5px;
          right: 5px;
          // color: rgba(0, 0, 0, 0.5);
        }
        .makerdui-selected {
          color: #ff7e00;
        }
        span {
          position: absolute;
          height: 20px;
          bottom: 0;
          left: 0;
          right: 0;
          font-size: 12px;
          text-align: center;
          line-height: 18px;
          background-color: rgba(0, 0, 0, 0.5);
          color: #ffffff;
          display: flex;
          align-items: center;
          justify-content: center;
          i {
            margin-right: 4px;
            color: #e4393c;
          }
        }
      }
      .add-img-item {
        position: relative;
        input {
          position: absolute;
          top: 0;
          left: 0;
          bottom: 0;
          right: 0;
          width: 100%;
          height: 100%;
          opacity: 0;
          background-color: transparent;
          z-index: 10;
        }
        i {
          position: absolute;
          top: 50%;
          left: 50%;
          font-size: 40px;
          color: #ff7e00;
          background-color: transparent;
          z-index: 1;
          transform: translateY(-50%) translateX(-50%);
        }
      }
    }
  }
  .select-footer {
    widows: 100vw;
    height: 9vh;
  }
}
</style>
<style>
.custom-class .nut-dialog-cancel {
  font-size: 16px !important;
  color: #1e1e1e !important;
}
</style>
